<?php

namespace app\admin\model\dealer;

use think\Model;


class MoneyLog extends Model
{

    

    

    // 表名
    protected $name = 'dealer_money_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    public function dealer()
    {
        return $this->belongsTo('app\admin\model\dealer\Dealer', 'dealer_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    /**
     * 经销商提现总额
     * @param int $dealer_id
     * @return float|int
     */
    public function getWithdrawAmount($dealer_id = 0, $where = []){
        $where_dealer = [];
        if($dealer_id != 0){
            $where_dealer['dealer_id'] = $dealer_id;
        }
        $return_amount = $this->with(['dealer'])->where($where)->where($where_dealer)->sum('money');
        return $return_amount;
    }
}
